package eu.robico.simulator.simulatorinterface;

import java.util.Observable;

import eu.robico.simulator.simulatorinterface.communication.Protocol.WheelStatus;

public class RobotStatus extends Observable
{
	public enum RobotStatusUpdate
	{
		BUZZERUPDATE,
		LEFTCOLORLANESENSORUPDATE,
		RIGHTCOLORLANESENSORUPDATE,
		LED1UPDATE,
		LED2UPDATE,
		SLEEPUPDATE,
		WHEELCONTROLUPDATE,
		LEFTWHEELUPDATE,
		RIGHTWHEELUPDATE,
		CROSSROADSSENSORUPDATE,
		LEFTSIDEEXITSENSORUPDATE,
		RIGHTSIDEEXITSENSORUPDATE
	}
	
	private boolean buzzer, colorLaneLeftSensor, colorLaneRightSensor, 
					crossRoadsSensor, led1, led2, sleep, wheelControl,
					leftSideExitSensor, rightSideExitSensor;
	
	private WheelStatus leftWheel, rightWheel;

	public static RobotStatus copyOf(RobotStatus original)
	{
		RobotStatus copy = new RobotStatus();
		copy.buzzer = original.buzzer;
		copy.colorLaneLeftSensor = original.colorLaneLeftSensor;
		copy.colorLaneRightSensor = original.colorLaneRightSensor;
		copy.crossRoadsSensor = original.crossRoadsSensor;
		copy.led1 = original.led1;
		copy.led2 = original.led2;
		if (original.hasLeftWheelValue())
			copy.leftWheel = original.leftWheel;
		if (original.hasRightWheelValue())
			copy.rightWheel = original.rightWheel;
		copy.sleep = original.sleep;
		copy.wheelControl = original.wheelControl;
		copy.leftSideExitSensor = original.leftSideExitSensor;
		copy.rightSideExitSensor = original.rightSideExitSensor;
		return copy;
	}
	
	public void reset()
	{
		buzzer = false;
		colorLaneLeftSensor = false;
		colorLaneRightSensor = false; 
		crossRoadsSensor = false;
		led1 = false; 
		led2 = false; 
		sleep = false; 
		wheelControl = false;
		leftWheel = null;
		rightWheel = null;
		leftSideExitSensor = false;
		rightSideExitSensor = false;
	}
	
	//Getters
	public boolean getBuzzer() { return buzzer;	}
	public boolean getColorLaneLeftSensor() { return colorLaneLeftSensor; }
	public boolean getColorLaneRightSensor() { return colorLaneRightSensor; }
	public boolean getCrossRoadsSensor() { return crossRoadsSensor; }
	public boolean getLed1() { return led1; }
	public boolean getLed2() { return led2; }
	public boolean getLeftSideExitSensor() { return leftSideExitSensor; }
	public boolean getRightSideExitSensor() { return rightSideExitSensor; }
	public boolean getSleep() {	return sleep;}
	public boolean getWheelControl() { return wheelControl; }
	public String getLeftWheelStatusString() { return leftWheel.toString(); }
	public String getRightWheelStatusString() {	return rightWheel.toString(); }
	public WheelStatus getLeftWheelStatus() { return leftWheel; }
	public WheelStatus getRightWheelStatus() {	return rightWheel; }
	
	//Tests
	public boolean hasLeftWheelValue() { return leftWheel != null; }
	public boolean hasRightWheelValue() { return rightWheel != null; }
	
	//Setters
	public void setBuzzer(boolean buzzer) 
	{ 
		this.buzzer = buzzer;
		setChanged();
		notifyObservers(RobotStatusUpdate.BUZZERUPDATE);
	}
	
	public void setColorLaneLeftSensor(boolean colorLaneLeftSensor) 
	{ 
		this.colorLaneLeftSensor = colorLaneLeftSensor;
		setChanged();
		notifyObservers(RobotStatusUpdate.LEFTCOLORLANESENSORUPDATE);
	}
	
	public void setColorLaneRightSensor(boolean colorLaneRightSensor) 
	{	
		this.colorLaneRightSensor = colorLaneRightSensor;
		setChanged();
		notifyObservers(RobotStatusUpdate.RIGHTCOLORLANESENSORUPDATE);
	}
	
	public void setCrossRoadsSensor(boolean crossRoadsSensor)
	{
		this.crossRoadsSensor = crossRoadsSensor;
		setChanged();
		notifyObservers(RobotStatusUpdate.CROSSROADSSENSORUPDATE);
	}
	
	
	public void setLed1(boolean led1) 
	{	
		this.led1 = led1;
		setChanged();
		notifyObservers(RobotStatusUpdate.LED1UPDATE);
	}
	
	public void setLed2(boolean led2) 
	{ 
		this.led2 = led2;
		setChanged();
		notifyObservers(RobotStatusUpdate.LED2UPDATE);
	}
	
	public void setLeftSideExitSensor(boolean sideExitSensor)
	{
		this.leftSideExitSensor = sideExitSensor;
		setChanged();
		notifyObservers(RobotStatusUpdate.LEFTSIDEEXITSENSORUPDATE);
	}
	
	public void setRightSideExitSensor(boolean sideExitSensor)
	{
		this.rightSideExitSensor = sideExitSensor;
		setChanged();
		notifyObservers(RobotStatusUpdate.RIGHTSIDEEXITSENSORUPDATE);
	}
	
	public void setSleep(boolean sleep) 
	{ 
		this.sleep = sleep;
		setChanged();
		notifyObservers(RobotStatusUpdate.SLEEPUPDATE);
	}
	
	public void setWheelControl(boolean wheelControl) 
	{
		this.wheelControl = wheelControl;
		setChanged();
		notifyObservers(RobotStatusUpdate.WHEELCONTROLUPDATE);
	}

	public void setLeftWheelStatus(WheelStatus status) 
	{
		this.leftWheel = status;
		setChanged();
		notifyObservers(RobotStatusUpdate.LEFTWHEELUPDATE);
	}

	public void setRightWheelStatus(WheelStatus status) 
	{
		this.rightWheel = status;
		setChanged();
		notifyObservers(RobotStatusUpdate.RIGHTWHEELUPDATE);
	}
}
